package com.wuyou.mid;


import java.util.Arrays;

/**
 * 817. 链表组件
 */
public class NumComponents {


    public int solution_1(ListNode head, int[] nums) {
        Arrays.sort(nums);
        int res = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if(nums[i] + 1 != nums[i + 1]){
                res ++;
            }
        }

        if (nums.length > 0) {
            res ++;
        }
        return res;
    }


}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}